// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   firstKind_delete_ok.java

package ecommerce.config.website;

import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class firstKind_delete_ok extends HttpServlet
{

	public firstKind_delete_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession(true);
		nseer_db_backup1 ecommerce_db = new nseer_db_backup1(dbApplication);
		try
		{
			if (ecommerce_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				int intRowCount = 0;
				String sqll = "select * from ecommerce_config_cols_first";
				ResultSet rs = ecommerce_db.executeQuery(sqll);
				rs.next();
				rs.last();
				intRowCount = rs.getRow();
				String del[] = new String[intRowCount];
				del = (String[])session.getAttribute("del");
				String first_kind_ID[] = new String[intRowCount];
				String first_kind_name[] = new String[intRowCount];
				String real_del[] = new String[intRowCount];
				int m = 0;
				int n = 0;
				if (del != null)
				{
					for (int i = 1; i <= intRowCount; i++)
						if (del[i - 1] != null)
						{
							real_del[n] = del[i - 1];
							n++;
							String sql2 = (new StringBuilder("select * from ecommerce_config_cols_first where id='")).append(del[i - 1]).append("'").toString();
							ResultSet rs2 = ecommerce_db.executeQuery(sql2);
							if (rs2.next())
							{
								first_kind_ID[i - 1] = rs2.getString("first_kind_ID");
								first_kind_name[i - 1] = rs2.getString("first_kind_name");
							}
							int col = 0;
							String sql3 = (new StringBuilder("select id from ecommerce_cols_bottom where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
							ResultSet rs3 = ecommerce_db.executeQuery(sql3);
							if (rs3.next())
								col++;
							sql3 = (new StringBuilder("select id from ecommerce_cols_top where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
							rs3 = ecommerce_db.executeQuery(sql3);
							if (rs3.next())
								col++;
							sql3 = (new StringBuilder("select id from ecommerce_colsa where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
							rs3 = ecommerce_db.executeQuery(sql3);
							if (rs3.next())
								col++;
							sql3 = (new StringBuilder("select * from ecommerce_config_cols_second where first_kind_ID='")).append(first_kind_ID[i - 1]).append("' and second_kind_name!=''").toString();
							rs3 = ecommerce_db.executeQuery(sql3);
							if (rs3.next())
								col++;
							sql3 = (new StringBuilder("select * from ecommerce_other where chain_id='")).append(first_kind_ID[i - 1]).append("'").toString();
							rs3 = ecommerce_db.executeQuery(sql3);
							if (rs3.next())
								col++;
							if (col == 0)
							{
								String sql = (new StringBuilder("delete from ecommerce_config_cols_first where id='")).append(del[i - 1]).append("'").toString();
								ecommerce_db.executeUpdate(sql);
								String sql4 = (new StringBuilder("delete from ecommerce_config_cols_second where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
								ecommerce_db.executeUpdate(sql4);
								sql = (new StringBuilder("delete from ecommerce_config_other_first where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
								ecommerce_db.executeUpdate(sql);
								sql4 = (new StringBuilder("delete from ecommerce_config_other_second where first_kind_ID='")).append(first_kind_ID[i - 1]).append("'").toString();
								ecommerce_db.executeUpdate(sql4);
							} else
							{
								first_kind_ID[m] = first_kind_ID[i - 1];
								first_kind_name[m] = first_kind_name[i - 1];
								m++;
							}
						}

				}
				ecommerce_db.commit();
				ecommerce_db.close();
				if (n == 0)
					response.sendRedirect("ecommerce/config/website/firstKind.jsp");
				else
				if (m < n && m != 0)
				{
					session.setAttribute("first_kind_ID", first_kind_ID);
					session.setAttribute("first_kind_name", first_kind_name);
					session.setAttribute("first_kind_count", (new StringBuilder(String.valueOf(m))).toString());
					response.sendRedirect("ecommerce/config/website/firstKind_delete_ok_a.jsp");
				} else
				if (m == n)
					response.sendRedirect("ecommerce/config/website/firstKind_delete_ok_b.jsp");
				else
				if (m == 0)
					response.sendRedirect("ecommerce/config/website/firstKind_delete_ok_c.jsp");
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
